package com.hualan.sfzy.service.impl.consult;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.consult.ConsultChargesMapper;
import com.hualan.sfzy.model.entity.ConsultCharges;
import com.hualan.sfzy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ConsultChargesServiceImpl implements BaseService<ConsultCharges> {
    @Autowired
    private ConsultChargesMapper mapper;

    @Override
    public int add(ConsultCharges entity) {
        return mapper.insert(entity);
    }

    @Override
    public int edit(ConsultCharges entity) {
        return mapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return mapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return mapper.deleteBatch(ids);
    }

    @Override
    public List<ConsultCharges> find() {
        return mapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, ConsultCharges entity) {
        PageHelper.startPage(pageNum, pageSize);
        List<ConsultCharges> list = mapper.select(entity);
        PageInfo<ConsultCharges> info = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, info.getPages());
        map.put(CommonConstant.TOTAL, info.getTotal());
        return map;
    }

    @Override
    public ConsultCharges findById(Integer id) {
        return mapper.selectById(id);
    }


    //  额外添加 删除分类时先判断是否还有咨询师在使用这个收费标准
    public List<ConsultCharges> selectPro(Integer id) {
        return mapper.selectPro(id);
    }


    // 小程序 根据咨询师 id 查询咨询师收费标准信息
    public List<ConsultCharges> findByConsultId(Integer id) {
        return mapper.findByConsultId(id);
    }
}
